<?php
class Registration_model extends CI_Model {

	function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

	function save_registration_request ($postvars)
	{	
		date_default_timezone_set('America/New_York');
		$created_date = date("Y-m-d");
		
		$data = array(
					'name' => $this->input->post('user_name'),
					'address' => $this->input->post('user_address'),
					'phone' => $this->input->post('user_phone'),
					'email' => $this->input->post('user_email'),
					'department' => $this->input->post('user_dept'),
					'institution' => $this->input->post('user_inst'),
					'info' => $this->input->post('user_info'),
										
					'request_date' => $created_date,
				);
		
		return $this->db->insert('vm_user_registration_requests',$data);
	}
	
	function get_registration_requests(){
			$this->db->order_by("request_date","desc");
			$query = $this->db->get("registration_requests");
			if ($query->num_rows() > 0) {
				$output = '<table border="0" cellspacing="5">';
				$output .= '<thead><tr>';
				$output .= '<th>Requester Name</th>';
      			$output .= '<th>Institution</th>';
      			$output .= '<th>Department</th>';
                $output .= '<th>Address</th>';
                $output .= '<th>Phone</th>';
                $output .= '<th>Email</th>';
                $output .= '<th>Additional Info</th>';
                $output .= '<th>Request Received Date</th>';
    			$output .= '</tr></thead><tbody>';
				
    			$cnt = 1;
    			foreach ($query->result() as $request_info) {
    				if($cnt%2 == 0){
						$output .= '<tr>';
						$output .= '<td>' . $request_info->name . '</td>';
						$output .= '<td>' . $request_info->institution . '</td>';
						$output .= '<td>' . $request_info->department . '</td>';
						$output .= '<td>' . $request_info->address . '</td>';
						$output .= '<td>' . $request_info->phone . '</td>';
						$output .= '<td>' . $request_info->email . '</td>';
						$output .= '<td>' . $request_info->info . '</td>';
						$output .= '<td>' . $request_info->request_date . '</td>';
						$output .= '</tr>';
    				}
    				else{
						$output .= '<tr>';
						$output .= '<td bgcolor="#99B2FF">' . $request_info->name . '</td>';
						$output .= '<td bgcolor="#99B2FF">' . $request_info->institution . '</td>';
						$output .= '<td bgcolor="#99B2FF">' . $request_info->department . '</td>';
						$output .= '<td bgcolor="#99B2FF">' . $request_info->address . '</td>';
						$output .= '<td bgcolor="#99B2FF">' . $request_info->phone . '</td>';
						$output .= '<td bgcolor="#99B2FF">' . $request_info->email . '</td>';
						$output .= '<td bgcolor="#99B2FF">' . $request_info->info . '</td>';
						$output .= '<td bgcolor="#99B2FF">' . $request_info->request_date . '</td>';
						$output .= '</tr>';
    				}
    				$cnt++;
				}
				$output .= '</tbody></table>';
				return $output;
			} else {
				return '<p>No registration requests received.</p>';
			}
	}

}
?>